# 构建阶段
FROM maven:3.8.7-eclipse-temurin-17 AS build
WORKDIR /app

# 1. 只复制必要的构建文件
COPY pom.xml .
COPY src ./src
COPY setting.xml /root/.m2/settings.xml

# 2. 下载依赖（利用Docker缓存）
RUN mvn -B dependency:go-offline

# 3. 构建应用（确保清理旧构建）
RUN mvn -B clean package && \
    ls -lR target/ && \
    jar tf target/*.jar | grep HelloController.class

# 运行阶段
FROM openjdk:17-oracle
WORKDIR /app
# 4. 明确指定目标JAR路径
COPY --from=build /app/target/*.jar app.jar
EXPOSE 8998
ENTRYPOINT ["java", "-jar", "app.jar"]